<template>
    <div class="eXinFuZai">
        <custom-dialog :title="bt" size="tiny" @dialogClose="dialogTableClose">
            <div class="cContentItem">
                <div>
                    <img src="@/assets/images/controlCenter/unSelect.png" v-if="selectCheck == false" @click="onSelect(true)" />
                    <img src="@/assets/images/controlCenter/select.png" v-if="selectCheck == true" @click="onSelect(false)" />
                    <label>启用恶性负载控制</label>
                </div>
                <div>
                    <!-- 没有小数 -->
                    <label>恶性负载限定值(W)：</label>
                    <el-input-number
                        placeholder="请输入"
                        style="width: 120px; margin-right: 10px"
                        :controls="true"
                        v-model="xdz"
                        :precision="0"
                        :min="0"
                        :max="13200"
                    ></el-input-number>

                    <el-button :loading="hqXdzLoading" type="primary" size="small" @click="hqXdz">获取</el-button>
                    <el-button :loading="hqXfLoading" type="primary" size="small" @click="hqXf">下发</el-button>
                </div>
                <div style="border-top: 1px solid #ddd; margin-top: 20px; padding-top: 20px">
                    <label>总负载(kW)：</label>
                    <!-- 0-13.20 两位小数-->
                    <el-input-number
                        placeholder="请输入"
                        style="width: 120px; margin-right: 10px"
                        :controls="true"
                        v-model="zfz"
                        :precision="2"
                        :min="0.0"
                        :max="13.2"
                    ></el-input-number>

                    <el-button :loading="zfzXdzLoading" type="primary" size="small" @click="zfzXdz">获取</el-button>
                    <el-button :loading="zfzXfLoading" type="primary" size="small" @click="zfzXf">下发</el-button>
                </div>
            </div>
        </custom-dialog>
    </div>
</template>

<script>
import customDialog from '@/components/customComponents/customDialog'
import {AjaxCommon} from '@/libs/apiCommon'
import {PopupCommon} from '@/libs/popupCommon'
export default {
    name: 'eXinFuZai',
    props: ['selectItem'],
    components: {
        customDialog
    },
    data() {
        return {
            bt: '负载设置',
            hqXdzLoading: false,
            hqXfLoading: false,
            zfzXdzLoading: false,
            zfzXfLoading: false,
            xdz: 0,
            zfz: 0.0,
            selectCheck: false
        }
    },
    computed: {},
    created() {
        const v = this.selectItem
        this.bt = `【${v.eq_name}】负载设置`
    },
    methods: {
        async zfzXf() {
            this.zfzXfLoading = true
            const selectItem = this.selectItem
            const data = await AjaxCommon(`/api/Eq/WriteMaxPower?eqid=${selectItem.eq_guid}&strSZ=${this.zfz}`, 'post', {})
            PopupCommon.notify('success', data.data.Message)
            this.zfzXfLoading = false
        },
        async hqXf() {
            this.hqXfLoading = true
            const selectItem = this.selectItem
            // 	恶性负载值（单位W）
            // 是否启用恶性负载
            const data = await AjaxCommon(
                `/api/Eq/WriteBadPower?eqid=${selectItem.eq_guid}&strSZ=${this.xdz}&bEXFZ=${this.selectCheck}`,
                'post',
                {}
            )
            PopupCommon.notify('success', '下发成功')
            this.hqXfLoading = false
        },
        // 获取限定值 ElectricRT/GetPMCRT id=fe11c468-a71c-47a5-9fb9-540bbb128875&sjx=25&cs=&T=01%3A30%3A55+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)
        async hqXdz() {
            this.hqXdzLoading = true
            const selectItem = this.selectItem
            // api/Eq/GetEqRtBadVal?eqid={eqid}&sjx={sjx}
            // 数据项（实时电量1、恶性负载25、读取最大负荷设置值26、正向无功电能68）
            const data = await AjaxCommon(`/api/Eq/GetEqRtBadVal?eqid=${selectItem.eq_guid}&sjx=25`, 'post', {})
            const v = data.data.Message
            const vSplit = v.split('|')
            this.xdz = vSplit?.[0] ?? ''
            if (vSplit?.[1]?.trim()?.toString()?.toUpperCase() === 'TRUE') {
                this.selectCheck = true
            } else {
                this.selectCheck = false
            }
            this.hqXdzLoading = false
        },
        async zfzXdz() {
            this.zfzXdzLoading = true
            const selectItem = this.selectItem
            const data = await AjaxCommon(`/api/Eq/GetEqRtBadVal?eqid=${selectItem.eq_guid}&sjx=26`, 'post', {})
            const v = data.data.Message
            const vSplit = v.split('|')
            this.zfz = vSplit?.[0] ?? ''
            this.zfzXdzLoading = false
        },
        onSelect(isTrue) {
            this.selectCheck = isTrue
        },
        dialogTableClose() {
            this.$emit('onClose', '')
        }
    }
}
</script>

<style lang="scss" scoped>
.cContentItem {
    font-size: 14px;
    padding: 0;
    background: #fff;
    width: 100%;
    padding: 20px;
    div {
        &:first-child {
            height: 16px;
            line-height: 16px;
            img {
                width: 16px;
                height: 16px;
            }
        }
        height: 28px;
        line-height: 28px;
        margin-bottom: 10px;
        text-align: left;
        img {
            float: left;
            margin-right: 10px;
            cursor: pointer;
        }
        label {
            float: left;
            width: 140px;
        }
        width: 100%;
    }
}
</style>